<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="../css/byking.css">
<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
	<div class="byking-form">
		<form class="layui-form" action="">
			
			<div class="layui-form-item">
				<label class="layui-form-label">旧密码</label>
				<div class="layui-input-inline">
					<input type="password" name="oldPassword" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
						class="layui-input">
				</div>
				
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">输入密码</label>
				<div class="layui-input-inline">
					<input type="password" name="password" required lay-verify="password" placeholder="请输入密码" autocomplete="off"
						class="layui-input">
						
				</div>
				<div class="layui-form-mid layui-word-aux">必须包含大小写字母,数字和特殊字符的组合,长度在8-20之间</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">确认密码</label>
				<div class="layui-input-inline">
					<input type="password" name="repassword" required lay-verify="password" placeholder="请再次输入密码" autocomplete="off"
						class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">必须包含大小写字母,数字和特殊字符的组合,长度在8-20之间</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn"  lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<!-- jQuery -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- jquery.cookie -->
	<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<!-- layer -->
	<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
	<!-- vue -->
	<script src="http://cdn.jsdelivr.net/vue/1.0.7/vue.min.js"></script>
	<script src="../js/byking.js"></script>
	<script src="../js/byking-verify.js"></script>
	<script src="../js/hostconfig.js"></script>
	<script src="../js/MD5.js"></script>
	<script src="../layui/layui.js"></script>

	<script>
		
		layui.use('form', function() {
			var form = layui.form();

			form.verify({  
				password: function(value) {
					if(!$bykingVerify.checkPassword(value)) {
						return '必须包含大小写字母,数字和特殊字符的组合,长度在8-20之间';
					}
				}
			});
			
			//监听提交
			form.on('submit(formDemo)', function(data) {
				//layer.msg(JSON.stringify(data.field));
				var data = data.field;
				if(data.password != data.repassword) {
					layer.msg('两次输入密码不一致，请重新输入!', {icon: 5});
					
					return false;
				}
				
				var newData = {
					username: $byking.getCookieValue("username"),
					newPassword: hex_md5(data.password),
					oldPassword: hex_md5(data.oldPassword),
					update_by:$byking.getUrlParam("userId")
				};
				$byking.postJSONWithToken($hostconfig.sysAuthHost+"/sso/pwd/modify",newData,function(data){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				},function(data){
					layer.msg(data.responseJSON.message, {icon: 5});
				});
				return false;
			});
		});
		
	</script>
</body>
</html>